package com.geovis.boot.exception.base;

import java.util.Map;
import java.util.TreeMap;

/**
 * 异常表达式
 * Created by l.wang on 2018年8月21日
 */
public class ErrorMap {

	public static final int MODEL_ALL = 0;
	public static final int MODEL_EMBEDDED = 1000000;
	public static final int MODEL_VIEWSTATUS = 2000000;
	
	/**
	 * 00xxx000 is a representative of exception level
	 */
	public static final int ERROR_OK = 200000;
	public static final int ERROR_ERROR = 400000;

	public final static int ERROR_ALL_CLIENT_ERROR = MODEL_EMBEDDED + ERROR_ERROR /* + 0 */;
	public final static int ERROR_ALL_CLIENT_NO_SUCH_REQUEST_HANDLING_METHOD_ERROR = MODEL_ALL + ERROR_ERROR + 1;
	public final static int ERROR_ALL_CLIENT_HTTP_REQUEST_METHOD_NOT_SUPPORTED_ERROR = MODEL_ALL + ERROR_ERROR + 2;
	public final static int ERROR_ALL_CLIENT_HTTP_MEDIA_TYPE_NOT_SUPPORTED_ERROR = MODEL_ALL + ERROR_ERROR + 3;
	public final static int ERROR_ALL_CLIENT_HTTP_MEDIA_TYPE_NOT_ACCEPTABLE_ERROR = MODEL_ALL + ERROR_ERROR + 4;
	public final static int ERROR_ALL_CLIENT_MISSING_PATH_VARIABLE_ERROR = MODEL_ALL + ERROR_ERROR + 5;
	public final static int ERROR_ALL_CLIENT_MISSING_SERVLET_REQUEST_PARAMETER_ERROR = MODEL_ALL + ERROR_ERROR + 6;
	public final static int ERROR_ALL_CLIENT_SERVLET_REQUEST_BINDING_ERROR = MODEL_ALL + ERROR_ERROR + 7;
	public final static int ERROR_ALL_CLIENT_CONVERSION_NOT_SUPPORTED_ERROR = MODEL_ALL + ERROR_ERROR + 8;
	public final static int ERROR_ALL_CLIENT_HTTP_MESSAGE_NOT_READABLE_ERROR = MODEL_ALL + ERROR_ERROR + 9;
	public final static int ERROR_ALL_CLIENT_HTTP_MESSAGE_NOT_WRITABLE_ERROR = MODEL_ALL + ERROR_ERROR + 10;
	public final static int ERROR_ALL_CLIENT_MISSING_SERVLET_REQUEST_PART_ERROR = MODEL_ALL + ERROR_ERROR + 11;
	public final static int ERROR_ALL_CLIENT_NO_HANDLER_FOUND_ERROR = MODEL_ALL + ERROR_ERROR + 12;
	public final static int ERROR_ALL_CLIENT_BIND_ERROR = MODEL_ALL + ERROR_ERROR + 13;
	public final static int ERROR_ALL_CLIENT_METHOD_ARGUMENT_NOT_VALID_ERROR = MODEL_ALL + ERROR_ERROR + 14;
	public final static int ERROR_ALL_CLIENT_TYPE_MISMATCH_ERROR = MODEL_ALL + ERROR_ERROR + 15;
	public final static int ERROR_ALL_CLIENT_RATE_LIMIT_EXCEEDED_ERROR = MODEL_ALL + ERROR_ERROR + 16;
	public final static int ERROR_ALL_CLIENT_TIMES_LIMIT_EXCEEDED_ERROR = MODEL_ALL + ERROR_ERROR + 17;
	
	
	public final static int ERROR_VIEWSTATUS_USER_DEFINED_PARAMS_NULL_ERROR = MODEL_VIEWSTATUS + ERROR_ERROR + 1;
	public final static int ERROR_USER_NAME_PARAMS_NULL_ERROR = MODEL_VIEWSTATUS + ERROR_ERROR + 2;
	public final static int ERROR_USER_NAME_PARAMS_ERROR = MODEL_VIEWSTATUS + ERROR_ERROR + 3;
	public final static int ERROR_TOKEN_NOTNULL_ERROR = MODEL_EMBEDDED + ERROR_ERROR + 1;

	//自定义回复
	public final static int CUSTOM_EXCEPTION_RETURN = ERROR_OK;
	

	private static final Map<Integer, String> errMap = new TreeMap<>();

	static {
		errMap.put(ERROR_ALL_CLIENT_NO_SUCH_REQUEST_HANDLING_METHOD_ERROR, "Not found");
		errMap.put(ERROR_ALL_CLIENT_HTTP_REQUEST_METHOD_NOT_SUPPORTED_ERROR, "Method not allowed");
		errMap.put(ERROR_ALL_CLIENT_HTTP_MEDIA_TYPE_NOT_SUPPORTED_ERROR, "Unsupported media type");
		errMap.put(ERROR_ALL_CLIENT_HTTP_MEDIA_TYPE_NOT_ACCEPTABLE_ERROR, "Not acceptable");
		errMap.put(ERROR_ALL_CLIENT_MISSING_PATH_VARIABLE_ERROR, "URI path error");
		errMap.put(ERROR_ALL_CLIENT_MISSING_SERVLET_REQUEST_PARAMETER_ERROR, "Required parameter is not present");
		errMap.put(ERROR_ALL_CLIENT_SERVLET_REQUEST_BINDING_ERROR, "Request bind error");
		errMap.put(ERROR_ALL_CLIENT_CONVERSION_NOT_SUPPORTED_ERROR,
				"No suitable editor or converter can be found for property");
		errMap.put(ERROR_ALL_CLIENT_HTTP_MESSAGE_NOT_READABLE_ERROR, "Read method failed");
		errMap.put(ERROR_ALL_CLIENT_HTTP_MESSAGE_NOT_WRITABLE_ERROR, "Write method failed");
		errMap.put(ERROR_ALL_CLIENT_MISSING_SERVLET_REQUEST_PART_ERROR,
				"Part of a \"multipart/form-data\" request identified by its name cannot be found");
		errMap.put(ERROR_ALL_CLIENT_NO_HANDLER_FOUND_ERROR, "DispatcherServlet can't find a handler for a request");
		errMap.put(ERROR_ALL_CLIENT_BIND_ERROR, "Argument bind error");
		errMap.put(ERROR_ALL_CLIENT_METHOD_ARGUMENT_NOT_VALID_ERROR, "Invalid method");
		errMap.put(ERROR_ALL_CLIENT_TYPE_MISMATCH_ERROR, "Argument type error");
		errMap.put(ERROR_ALL_CLIENT_RATE_LIMIT_EXCEEDED_ERROR, "Rate limit exceeded");
		errMap.put(ERROR_ALL_CLIENT_TIMES_LIMIT_EXCEEDED_ERROR, "Times limit exceeded");

		errMap.put(ERROR_VIEWSTATUS_USER_DEFINED_PARAMS_NULL_ERROR, "{0}");
		errMap.put(ERROR_USER_NAME_PARAMS_ERROR, "{0}");
		errMap.put(ERROR_USER_NAME_PARAMS_NULL_ERROR, "{0}");

		//自宝义回复
		errMap.put(CUSTOM_EXCEPTION_RETURN,"{0}");

	}

	public static String code2Desc(int code) {
		return errMap.get(code);
	}
}
